package com.yomahub.liteflow.example.xstream.converter;

import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.yomahub.liteflow.example.xstream.Author;

/**
 * @program: liteflow-example
 * @description:
 * @author: yyyyjinying
 * @create: 2023-09-25 18:19
 **/
public class AuthorConverter implements SingleValueConverter {
//    // 从Author中提取字符串：
//    @Override
//    public String toString(Object obj) {
//        return ((Author) obj).getName();
//    }
//
////    获取一个String并返回一个Author
//    @Override
//    public Object fromString(String name) {
//        return new Author(name);
//    }
//
//    // XStream它可以处理哪些类型：
//    @Override
//    public boolean canConvert(Class type) {
//        return type.equals(Author.class);
//    }
    @Override
    public String toString(Object obj) {
        return ((Author) obj).getName();
    }
    @Override
    public Object fromString(String name) {
        return new Author(name);
    }
    @Override
    public boolean canConvert(Class type) {
        return type.equals(Author.class);
    }
}
